package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.PacketMark
import de.baumann.browser.api.net.vo.PacketStatus
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IGetPacksView
import de.baumann.browser.model.PackModel

class GetPacksPresenter : BasePresenter<IGetPacksView>() {

    private val packModel = PackModel()

    fun getPackets1(token: String) {
        this.packModel.getPackets1(view.local, token)
                .subscribe(object : OdinObserver<PacketMark>(view) {
                    override fun onSuccess(data: PacketMark?) {
                        if (view != null && data != null) {
                            view.setPacket(data)
                        }
                    }
                })
    }

    fun rePacket(packId: Int) {
        this.packModel.rePacket(packId)
                .subscribe(object : OdinObserver<PacketStatus>(view) {
                    override fun onSuccess(data: PacketStatus?) {
                        if (view != null && data != null) {
                            view.openPacket(packId, data.assistanceUrl, data.amount)
                        }
                    }
                })
    }

}